﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ServiceModel.Activation;
using System.ServiceModel;
using System.IO;
using System.Globalization;

namespace COFE.Web.Services
{
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    public class EventServices : IEventServices
    {
        public Stream GetEventList(string identifier, string json)
        {
            return ServicesUtils.ExecuteAndReturn<string, Stream>(
                (d) =>
                {
                    DateTime day = DateTime.ParseExact(d, EventList.ParseDateTimeFormat, 
                        CultureInfo.CurrentCulture);
                    EventList elist = EventList.ForDay(day);
                    return EncodeObjectUtils.EncodeObject(elist, json);
                }, identifier); throw new NotImplementedException();
        }

        public Stream GetTodayEventList(string json)
        {
            string redirectPath = "/events/" + 
                DateTime.Now.ToString(EventList.ParseDateTimeFormat);            
            ServicesUtils.SetRedirect(redirectPath, true);
            return null;
        }
    }
}